<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>79_80继承</title>
		<script>
			/* 
				封装-安全性
				继承 -扩展性
				多态-灵活性
			 */
			class Dog {
				constructor(name) {
					this.name = name;
				}
				sayHello() {
					console.log(this.name, "汪汪汪...");
				}
			}
			class Cat {
				constructor(name) {
					this.name = name;
				}
				sayHello() {
					console.log(this.name, "喵喵秒...");
				}
			}

			const dog = new Dog("大旺");
			const cat = new Cat("小喵");
			dog.sayHello();
			cat.sayHello()

			class Animal {
				constructor(name) {
					this.name = name;
				}

				sayHello() {
					console.log(this.name, "在叫...");
				}
			}

			class Dog1 extends Animal {
				// 在子类中，可以通过创建同名方法来重写父类的方法
				sayHello() {
					console.log("汪汪汪")
				}
			}
			class Cat1 extends Animal {
				//重写构造函数
				constructor(name, age) {
					//重写构造函数时，构造函数的第一行代码必须为super()
					super(name) //调用父类的构造函数
					this.age = age;
				}
				
				sayHello(){
					// 调用一下父类的sayHello
					super.sayHello() //在方法中可以使用super来引用父类的方法
					console.log("喵喵");
				}
			}

			const cat1 = new Cat1("喵咪");
			const dog1 = new Dog1("望望...", 11)
			cat1.sayHello()
			dog1.sayHello()
		</script>
	</head>
	<body>
	</body>
</html>